Zepto(function ($) {
  var zOrderInfoId = sessionStorage.getItem("zOrderInfoId")
  window.onload = function () {
    /**
     * 配置微信config
     *
     */
    getInitConfig();

    getOrderDetails();
  }
  var allprice ="";
  var outTradeNo = "";//总订单号
  // $("body").screenTop = 0;
  $(".nav-header").on("click", ".back", function (e) {
    window.history.go(-1);
  });
  /**
   * /wxmall/order/selectOrderInfo
   *
   */
  function getOrderDetails() {
    $.ajax({
      type: 'GET',
      url: getUrl + '/wxmall/order/selectOrderInfo',
      data: {
        "zOrderInfoId": zOrderInfoId
      },
      dataType: 'json',
      timeout: 15000,
      headers: headers("order.selectOrderInfo"),
      success: function(data){
        initView(data)
      },
      error: function(xhr, type){
      }
    });
  }
  function initView(data) {
    console.log(data);
    if(!data.success){
      return
    }
    var data1 = data.data;
    // alert(data1.zorder_no);
    outTradeNo = data1.zorder_no;
    $(".order-name")[0].innerHTML= data1.receiver_name;
    $(".address-phone")[0].innerHTML= data1.contact_mobile;
    $(".address")[0].innerHTML= data1.detailed_address;
    if(data1.post_money != ""){
      $("#post_money")[0].innerHTML= "(含运费:￥"+data1.post_money+")";
    }
    $(".red-goods")[0].innerHTML = "￥" + data1.order_total_money;
    $("#goodsList").html("");
    var goodslist = data1.orderGoodsInfo;
    if(goodslist.length > 0 ){
      var html = "";
      var allnumber = "0";
      var allpice = "0";
      for(var j = 0; j< goodslist.length ; j++){
        var picUrl = "";
        if(goodslist[j].picUrl != null&& goodslist[j].picUrl != undefined){
          picUrl = imgUrl + goodslist[j].picUrl;
        }
        var goods_name = "";
        if(goodslist[j].goods_name != null&& goodslist[j].goods_name != undefined){
          goods_name = goodslist[j].goods_name;
        }
        var specification = "";
        if(goodslist[j].specification != null&& goodslist[j].specification != undefined){
          specification = goodslist[j].specification;
        }
        var price = "";
        var prices= 0;
        if(goodslist[j].price != null&& goodslist[j].price != undefined){
          price ="￥" + goodslist[j].price;
          prices = parseInt(goodslist[j].price);
        }
        var discount_price = "";
        if(goodslist[j].discount_price != null&& goodslist[j].discount_price != undefined){
          discount_price ="￥" + goodslist[j].discount_price;
        }
        var number = "";
        var numbers = 0 ;
        if(goodslist[j].number != null&& goodslist[j].number != undefined){
          number ="X" + goodslist[j].number;
          allnumber = parseInt(allnumber) + parseInt(goodslist[j].number);
          numbers = parseInt(goodslist[j].number);
        }
        var a = parseInt(numbers);
        var b = parseInt(prices);
        console.log(a);
        allpice =parseInt(allpice) + parseInt(numbers)*parseInt(prices);
        html += '<div class="goods-list">\n' +
            '                            <div class="left"><img src="'+picUrl+'" /></div>\n' +
            '                            <div class="center">\n' +
            '                                <div class="center-content">\n' +
            '                                    <div class="goods-desc">'+goods_name+'</div>\n' +
            '                                    <div class="goods-specification">'+specification+'</div>\n' +
            '                                </div>\n' +
            '                            </div>\n' +
            '                            <div class="right">\n' +
            '                                <div class="goods-prise"><span class="z-price">'+price+'</span><span class="s-price">'+discount_price+'</span></div>\n' +
            '                                <div class="goods-num">'+number+'</div>\n' +
            '                                <div class="refund"></div>\n' +
            '                            </div>\n' +
            '                        </div>';
      }
      $("#goodsList").append(html);
      $("#allnumber")[0].innerHTML= allnumber;
      $(".red-goods")[0].innerHTML ="￥" + allpice;
      allprice = allpice;
    }
    $("#order_no")[0].innerHTML =data1.zorder_no
    $("#addTime")[0].innerHTML =data1.addTime
  }

  /**
   * 立即付款
   *
   */
  $(".glo").on("click",".comfire-tocart",function () {
    getorderlist();
  });

  /**
   * 立即购买
   *
   */
  function getorderlist() {
    var data = {
      "totalFee": allprice,
      "outTradeNo":outTradeNo
    };
    $.ajax({
      type: 'POST',
      url: getUrl + '/wxmall/pay/prepay',
      data: JSON.stringify(data),
      dataType: 'json',
      timeout: 15000,
      headers: headers("pay.prepay"),
      contentType:'application/json',
      success: function(data){
        if(data.success)
          preinvokes(data.data);
        else
          alert(resp.msg);
      },
      error: function(xhr, type){
        alert(JSON.stringify(xhr));
        alert(JSON.stringify(type));
      }
    });
  }
  /**
   * 取消订单
   *
   */
  $(".glo").on("click",".add-tocart",function () {

  });
});